package com.obelisco.vista.inicio;

import javax.servlet.http.HttpSession;

import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.app.Window;
import nextapp.echo2.webcontainer.ContainerContext;
import nextapp.echo2.webcontainer.DefaultServerDelayMessage;

import com.obelisco.comunes.ContextoObelisco;
import com.obelisco.comunes.ContextoObeliscoImpl;
import com.obelisco.vista.estilos.Styles;
import com.obelisco.vista.herramientas.ManejadorUI;

/**
 * Application instance implementation.
 */
public class Aplicacion extends ApplicationInstance {
	
	public static String ID_SPRING_CONTEXT = "springContext";
	public static String ID_OBELISCO_CONTEXT = "obeliscoContext";
	
	private ManejadorUI manejadorUI;
	
	private ContextoObelisco contexto;

	public static Aplicacion getApp() {
		return (Aplicacion) ApplicationInstance.getActive();
	}

	public static Aplicacion getCurrent()
	{		
		return (Aplicacion) ApplicationInstance.getActive();
	}

	public Window init() {		
		setStyleSheet(Styles.DEFAULT_STYLE_SHEET);		
		contexto = new ContextoObeliscoImpl();
	    ContainerContext cc = (ContainerContext) this.getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);   	
		cc.setServerDelayMessage(new DefaultServerDelayMessage("Espere, Por Favor..."));
		manejadorUI.iniciar();    	
    	return manejadorUI; 
	}

    public HttpSession getSession()
	{
		return ((ContainerContext)getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME)).getSession();
	}	
	
	public static ManejadorUI getManejadorUI()
	{
		return getCurrent().manejadorUI;
	}

	public void setManejadorUI(ManejadorUI manejadorUI) {
		this.manejadorUI = manejadorUI;
	}

    public void processFatalException(Exception ex) {
        ex.printStackTrace();        
    }

    public ContextoObelisco getContexto() {
		return contexto;
	}

	public void setContexto(ContextoObelisco contextoCumlaude) {
		this.contexto = contextoCumlaude;
	}
	
}
